<?php

namespace addons\qingdongams\controller;

use addons\qingdongams\model\Equipment as EquipmentModel;

/**
 * @desc 操作文档：https://doc.fastadmin.net/qingdongams
 * @desc 软件介绍：https://www.fastadmin.net/store/qingdongams.html
 * @desc 售后微信：qingdong_crm
 */
/**
 * 产品设备
 */
class Equipment extends StaffApi {
	protected $noNeedLogin = [];
	protected $noNeedRight = [];


	//获取设备详情
	public function getEquipDetail(){
	    $code = input('code','');
	    if(!$code){
	        $this->error('缺少参数设备码！');
        }
	    // 设备详情
        $product = EquipmentModel::where(['number'=>$code])->with(['product','customerProduct'=>['customer']])->find();
        if(empty($product)){
	        $this->error('产品信息不存在');
        }
        $workLogistic = [];
	    // 工单维修记录
	    if(isset($product['customer_product']['cid'])){
	        $cid = intval($product['customer_product']['cid']);
            $where="FIND_IN_SET($cid, w.customer_product_id)";
            $workLogistic = \addons\qingdongams\model\Workorder::alias('w')
                ->where($where)->join('qingdongams_workorder_logistics','l.workorder_id=w.id','left')->order('w.id asc')->select();
        }
        $data = [
            'info'  =>  $product,
            'logic' =>  $workLogistic
        ];
	    $this->success('请求成功',$data);
    }





}
